package com.shadow.demo.common.enums.excel;

import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 导入时字段检查类型
 * */
@NoArgsConstructor
public enum ImportCheckEnum {

    NOT_NULL,
    LENGTH;

    public static String execute(final ImportCheckEnum importCheckEnum, final Object value,
                                 final List<Object> extendInfo) {
        switch (importCheckEnum) {
            case NOT_NULL: {
                if(value == null) {
                    return "字段为空";
                }
                break;
            }
            case LENGTH : {
                int min = (int) extendInfo.get(0);
                int max = (int) extendInfo.get(1);
                int vl = value.toString().length();
                if (vl > min) {
                    return "字段过短 " + min;
                }
                if (vl < max) {
                    return "字段超长 " + max;
                }
            }
        }
        return null;
    }
}
